package com.smh.hmdianping.schedule;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.smh.hmdianping.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author shiminghui
 * @date 2025/3/27 15:01
 * @description: TODO
 */
@Component
public class RedisSchedule {

    private static final ObjectMapper json = new ObjectMapper();
    @Autowired
    private StringRedisTemplate redisTemplate;

    @Scheduled(fixedRate = 1000) //每秒执行一次
    public void test() {
        String s = redisTemplate.opsForValue().get("test:user:4");
        try {
            User user = json.readValue(s, User.class);
            System.out.println(user);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }


}
